import bank.*;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ThreadLocalRandom;

public class Program {

	public static void main(String[] args) {
		Bank bank = new Bank();
		String[] names = { "noby", "pizza delivery guy", "kevin", "catalysts", "liselotte", "monalisa", "herbert" };
		
		for (String name: names) {
			bank.register(new Account(name, 10000));
		}
		
		for (int i = 0; i < ThreadLocalRandom.current().nextInt(1, 5); i++) {
			Timer timer = new Timer();
			timer.scheduleAtFixedRate(new TimerTask() {
				long t0 = System.currentTimeMillis();
			
				@Override
				public void run() {
					if (System.currentTimeMillis() - t0 > 20 * 1000) {
						this.cancel();
						timer.cancel();
						timer.purge();
					} else {
						bank.commissionRandomTransaction();
					}
				}
			}, 0, 1000 * ThreadLocalRandom.current().nextInt(1, 5));
		}
	}

}